package com.senlan.water.controller.project;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.senlan.water.common.result.BaseResult;
import com.senlan.water.dao.domain.Project;
import com.senlan.water.dao.service.ProjectService;
import com.senlan.water.dto.project.ProjectAddDTO;
import com.senlan.water.dto.project.ProjectEditDTO;
import com.senlan.water.dto.project.ProjectSearchDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/project")
@Slf4j
@SaCheckLogin
public class ProjectController {

    @Resource
    private ProjectService projectService;

    /**
     * 新增
     * @param addDTO
     * @return
     */
    @PostMapping("add")
    public BaseResult<Boolean> add(@RequestBody ProjectAddDTO addDTO){
        return BaseResult.data(projectService.addNew(addDTO));
    }

    /**
     * 编辑
     * @param editDTO
     * @return
     */
    @PostMapping("edit")
    public BaseResult<Boolean> edit(@RequestBody ProjectEditDTO editDTO){
        return BaseResult.data(projectService.editById(editDTO));
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @GetMapping("delete")
    public BaseResult<Boolean> delete(@RequestParam("id") Long id){
        return BaseResult.data(projectService.deleteById(id));
    }

    /**
     * 分页查询
     * @param searchDTO
     * @return
     */
    @PostMapping("getPage")
    public BaseResult<Page<Project>> getPage(@RequestBody ProjectSearchDTO searchDTO){
        return BaseResult.data(projectService.getPage(searchDTO));
    }

    /**
     * 查询全部
     * @return
     */
    @PostMapping("getAll")
    public BaseResult<List<Project>> getAll(){
        return BaseResult.data(projectService.list());
    }
}
